package com.example.sprinboot_03_thymeleaf.controller;


import com.example.sprinboot_03_thymeleaf.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController {
    @RequestMapping("/test")
    public String index(Model model) {
        model.addAttribute("message", "http://www.ityouknow.com");
        return "hello";
    }

    @RequestMapping("/test2")
    public String inlinecommon(Model model) {
        model.addAttribute("userName", "neo");
        return "Stringtest";
    }

    @RequestMapping("/test3")
    public String ifunless(Model model,String flag) {
        model.addAttribute("flag", flag);
        return "if";
    }

    @RequestMapping("/test4")
    public String test4(Model model) {
        List<User> list=new ArrayList<>();

        list.add(new User("大牛",12,"123456"));
        list.add(new User("小牛",6,"123563"));
        list.add(new User("纯洁的微笑",66,"666666"));
        model.addAttribute("list", list);
        return "list";
    }

    @RequestMapping("/test5")
    public String url(Model model) {
        model.addAttribute("type", "link");
        model.addAttribute("pageId", "springboot/2022/03/30/");
        model.addAttribute("img", "https://fc5tn.baidu.com/it/u=188818894,1323916671&fm=202");
        return "url";
    }

    @RequestMapping("/test6")
    public String switchcase(Model model) {
        model.addAttribute("sex", "woman");
        return "switch";
    }

    @RequestMapping("/test7")
    public String inline(Model model) {
        model.addAttribute("userName", "neo");
        model.addAttribute("userId","15");
        return "inline";
    }
}